package tree.test559;

import java.util.List;

/**
 * @author code_yc
 * @version 1.0
 * @date 2020/7/18 10:39
 */
public class Solution1 {

    class Node {
        public int val;
        public List<Node> children;

        public Node() {}

        public Node(int _val) {
            val = _val;
        }

        public Node(int _val, List<Node> _children) {
            val = _val;
            children = _children;
        }
    }

    int max = 0;

    public int maxDepth(Node root) {
        if (root == null) return 0;
        dfs(root, 1);
        return max;
    }

    private void dfs(Node root, int c) {
        if (root.children.size() == 0) {
            max = Math.max(max, c);
            return;
        }
        for (Node n : root.children) {
            dfs(n, c + 1);
        }
    }
}
